﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace ProjectNocturnalFool
{
    public class Particle
    {
        public Texture2D Texture { get; set; }
        public Vector2 Position { get; set; }
        public Vector2 Direction { get; set; }
        public float Angle { get; set; }
        public float AngularVelocity { get; set; }
        public Color Color { get; set; }    
        public float Size { get; set; }
        public int TTL { get; set; }
        private int maxTTL;
        public Velocity velocityParticle;

        public Particle(Texture2D texture, Vector2 position, Vector2 direction,
            float angle, float angularVelocity, Color color, float size, int ttl, Velocity vel)
        {
            Texture = texture;
            Position = position;
            Direction = direction;
            Angle = angle;
            AngularVelocity = angularVelocity;
            Color = color;
            Size = size;
            TTL = ttl;
            maxTTL = ttl;
            velocityParticle = vel;
        }

        public void Update()
        {
            TTL--;
            velocityParticle.Update();

            Position += Direction * velocityParticle.currentSpeed;
            Angle += AngularVelocity;
        }

        public void Draw()
        {
            Rectangle sourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
            Vector2 origin = new Vector2(Texture.Width / 2, Texture.Height / 2);


            //this.Color.A = 0.2;


            TacticsGame.Instance.spriteBatch.Draw(Texture, Position, sourceRectangle, this.Color * ((float)TTL/maxTTL),
                Angle, origin, Size, SpriteEffects.None, 0f);
        }
    }

}
